<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport"
		content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
	<title>title</title>
	<link rel="stylesheet" type="text/css" href="../css/bootstrap.min.css">
	<link rel="stylesheet" type="text/css" href="../css/api.css" />
	<link rel="stylesheet" type="text/css" href="../css/aui.css" />
	<link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
	<link rel="stylesheet" type="text/css" href="../css/icons.css" />
	<script src="../script/jquery-1.9.1.min.js"></script>
	<script src="../script/bootstrap.min.js"></script>
	<style>
		.table tr:first-child {
			background: url(static/img/tableheader-bg.gif) no-repeat left top;
			background-color: #DCE9F2;
			border-top: 1px solid #CBD6DE;
			border-bottom: 1px solid #ADBECB;
			color: #467aa7;
			font-size: 13px;
			font-weight: bold;
		}

		.table {
			margin-bottom: 15px;
			width: 100%;
			border-collapse: collapse;
			font-size: 13px;
			margin-bottom: 15px;
			width: 100%;
			border-collapse: collapse;
		}

		.table td {
			height: 20px;
			text-align: center;
			border: 1px solid #CBD6DE;
			padding: 0;
			margin: 0;
			vertical-align: middle !important;
		}

		.hide {
			display: none;
		}

		.c1 {
			position: fixed;
			top: 0;
			bottom: 0;
			left: 0;
			right: 0;
			background: rgba(0, 0, 0, .5);
			z-index: 2;
		}

		.c2 {
			background-color: white;
			position: fixed;
			width: 350px;
			height: 300px;
			top: 50%;
			left: 50%;
			z-index: 3;
			margin-top: -150px;
			margin-left: -175px;
			padding-top: 2%;
			padding-left: 2%;
			overflow-y: auto;
			white-space: nowrap;
		}
	</style>
</head>

<body>
	<header class="aui-bar aui-bar-nav main-header">
		<a class="aui-pull-left aui-btn" tapmode onclick="closeWin();">
			<span class="aui-iconfont aui-icon-left"></span>
		</a>
		<div class="aui-title" id="title">
			选择处理人
		</div>
	</header>
	<div class="aui-bar aui-bar-nav sub-header"></div>
	<div class="aui-content aui-margin-b-15" style="margin-top:50px;padding-bottom: 50px;">
		<div class="white_background">
			<div id="modal">
				<p style="margin-left: 10px;font-size: 0.8rem;font-weight: 500;color: #212121;text-align: center;">
					存在异常问题，请选择处理人</p>
				<ul class="aui-list aui-form-list" style="margin-top: 4%;">
					<li class="aui-list-item">
						<div class="aui-list-item-inner">
							<div class="aui-list-item-label" style="width:80%">审核区域负责人：</div>
							<div class="aui-list-item-input">
								<select id="processors" onchange="changeprocessors()">
								</select>
							</div>
						</div>
					</li>
					<li class="aui-list-item" style="display: none;">
						<div class="aui-list-item-inner">
							<div class="aui-list-item-label">整改措施：</div>
							<div class="aui-list-item-input">
								<input type="text" id="measures"></input>
							</div>
						</div>
					</li>
					<li class="aui-list-item">
						<div class="aui-list-item-inner">
							<div class="aui-list-item-label" style="width:75%">要求完成时间：</div>
							<div class="aui-list-item-input">
								<input type="text" id="finishDate" onclick="showTime2()">
							</div>
						</div>
					</li>
					<li class="aui-list-item">
						<div class="aui-list-item-inner">
							<div class="aui-list-item-label" style="width:75%">不符合项描述：</div>
							<div class="aui-list-item-input">
								<textarea id="countermeasure" onblur="changeCountermeasure()"></textarea>
							</div>
						</div>
					</li>
				</ul>

			</div>
			<div id="myTabContent" class="tab-content">
				<div class="tab-pane fade in active" id="item">
					<div style="background-color:white; height: 100%;width: 100%;">
						<table id="chkItemTable" class="table" style="width:200%;font-size: 0.6rem;">
							<thead id="chkItemTableHead">
							</thead>
							<tbody id="chkItemTableBody">
							</tbody>
							<tbody id="chkItemTableBehind">
							</tbody>
						</table>
						<div class="aui-content aui-content-padded" style="text-align:center;margin-bottom: 5%">
							<p>
							</p>
							<div class="aui-btn aui-btn-info" onclick="doSubmit()" id="submitButton"
								style="width: 100%;height: 100%;">
								<span class="aui-iconfont" style="font-size: 20px;">提交数据</span>

							</div>
							<p></p>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript" src="../script/hammer.min.js"></script>
<script type="text/javascript" src="../script/clickThrottle.js"></script>
<script>
	var citemHtml = ""
	var citemList = [];
	var areaCodeList = [];
	var type = "";
	var taskState = "";
	var areaSysid = "";
	var measures = "";
	var actualBeginDate = "";
	var actualEndDate = "";
	var taskId = "";
	var josnList = [];

	apiready = function () {
		areaCodeList = api.pageParam.areaCodeList;
		citemList = api.pageParam.citemList;
		type = api.pageParam.type;
		taskState = api.pageParam.taskState;
		measures = api.pageParam.measures;
		actualBeginDate = api.pageParam.actualBeginDate;
		actualEndDate = api.pageParam.actualEndDate;
		taskId = api.pageParam.taskId;
		josnList = api.pageParam.josnList;
		areaSysid = api.pageParam.areaSysid;
		picNames = api.pageParam.picNames;
		console.log('190:' + taskId)

		doSearchProcessors(areaCodeList, citemList);
		if (citemList.length > 0) {
			var html = "";
			var html1 = "";
			html1 += "<tr id='tr1' color: #467aa7;>";
			html1 += "<td width='30%' algin='center'>异常项</td>";
			html1 += "<td width='20%' algin='center'>不符合项描述</td>";
			html1 += "<td width='18%' algin='center'>整改人</td>";
			html1 += "<td width='32%' algin='center'>整改时间</td>";
			html1 += "</tr>"
			$api.html($api.byId("chkItemTableHead"), html1);
			str = "";
			if (citemList != undefined) {
				//遍历
				for (var i = 0; i < citemList.length; i++) {
					str += "<tr >"
						+ "<td width='30%' algin='center'>"
						+ citemList[i].itemName +
						"</td>"
						+ "<td width='20%' algin='center'>"
						+ "<div>"
						+ "<input style='font-size:0.6rem;' type='text' id = 'countermeasure" + i + "'>"
						+ "</div>"
						+ "</td>"
						+ "<td width='18%' algin='center'>"
						+ "<div>"
						+ "<select style='font-size:0.6rem;' id = 'processors" + i + "'>"
						+ "</select>"
						+ "</div>"
						+ "</td>"
						+ "<td width='32%' algin='center'>"
						+ "<div>"
						+ "<input style='font-size:0.6rem;' type='text' id='finishDate" + i + "' onclick='showTime3(" + i + ")'>"
						+ "</div>"
						+ "</td>"
						+ "</tr >"
				}
			}
			$("#chkItemTableHead").append(str);
		}
	};


	function doSearchProcessors(areaId, citemList) {
		var un = localStorage.getItem('un');
		var serverUrl = localStorage.getItem('serverUrl');
		var url = serverUrl + "/app/getUtilComboxList";
		var data = {
			values: { ////以表单方式提交参数（JSON对象）
				tablename: "lpa_bas_area_user",
				column_name: "name",
				column_value: "code",
				condition: "area_gid = '" + areaId + "'",
				un: un
			}
		};
		api.ajax({
			url: url,
			method: 'post',
			dataType: 'json',
			timeout: 300,
			returnAll: false,
			async: false,
			data: data
		}, function (ret, err) {
			if (ret) {
				var data = JSON.stringify(ret);
				var map = eval("(" + data + ")");
				var list = eval(map.list);
				var html = "";
				this.lpaChkPeoList = list;
				for (var i = 0; i < list.length; i++) {
					html += "<option value='" + list[i].value + "'>" + list[i].label + "</option>";
				}
				$api.html($api.byId("processors"), html);
				citemHtml = html
				for (var i = 0; i < citemList.length; i++) {
					var processorsId = "processors" + i;
					$api.html($api.byId(processorsId), html);
				}
			}

		});
	}

	function changeprocessors() {
		var selectElement = $("#processors").val();
		for (var j = 0; j < citemList.length; j++) {
			var itemid = "#processors" + j
			$(itemid).val(selectElement)
		}
	}

	function changeCountermeasure() {
		var countermeasure = $("#countermeasure").val();
		for (var j = 0; j < citemList.length; j++) {
			var countermeasureId = "#countermeasure" + j
			$(countermeasureId).val(countermeasure)
		}
	}


	function showTime2() {
		var moduleTimer = api.require('moduleTimer');
		moduleTimer.showTimer({
			startTime: '2000-01-1 00:00',//可选择的起始时间
			endTime: '2099-12-31 23:59',//可选择的结束时间
			timeFormat: 'yyyy-MM-dd HH:mm:ss',//返回的时间格式，如果不传默认是yyyy-MM-dd HH:mm:ss
			selColor: '#079962'//选中的颜色值
		}, function (ret, err) {
			var finishDate = ret;
			var text = document.getElementById("finishDate");
			text.value = finishDate;
			for (var j = 0; j < citemList.length; j++) {
				var finishDateId = "#finishDate" + j
				$(finishDateId).val(finishDate)
			}
		});
	}

	function showTime3(i) {
		var moduleTimer = api.require('moduleTimer');
		moduleTimer.showTimer({
			startTime: '2000-01-1 00:00',//可选择的起始时间
			endTime: '2099-12-31 23:59',//可选择的结束时间
			timeFormat: 'yyyy-MM-dd HH:mm:ss',//返回的时间格式，如果不传默认是yyyy-MM-dd HH:mm:ss
			selColor: '#079962'//选中的颜色值
		}, function (ret, err) {
			var finishDate = ret;
			var finishDateId = "finishDate" + i;
			var text = document.getElementById(finishDateId);
			text.value = finishDate;
		});
	}

	function doSubmit() {
		if (!clickThrottle()) {
			return;
		}
		// var type = type
		// var taskState = this.taskState;
		var processors = document.getElementById("processors").value;
		// var areaSysid = areaCodeList;
		// var measures = measures;
		var finishDate = document.getElementById("finishDate").value;
		var countermeasure = document.getElementById("countermeasure").value;
		// var taskId = taskId;
		if (processors == "" || processors == null || processors == undefined) {
			api.toast({
				msg: '请选择审核区域负责人！',
				duration: 3000
			});
			return;
		}
		// if (countermeasure == "" || countermeasure == null || countermeasure == undefined) {
		// 	api.toast({
		// 		msg: '请填写不符合项描述！',
		// 		duration: 3000
		// 	});
		// 	return;
		// }
		// if (finishDate == "" || finishDate == null || finishDate == undefined) {
		// 	api.toast({
		// 		msg: '请选择要求完成时间！',
		// 		duration: 3000
		// 	});
		// 	return;
		// }
		var citemListNew = []
		if (citemList.length > 0) {
			for (var k = 0; k < citemList.length; k++) {
				var text = "#processors" + k
				var itemid = $(text).val()
				var text1 = "#countermeasure" + k
				var countermeasures = $(text1).val()
				var text2 = "#finishDate" + k
				var finishDates = $(text2).val()
				if (itemid == "" || itemid == null || itemid == undefined) {
					api.toast({
						msg: '请选择【' + citemList[k].itemName + '】整改人！',
						duration: 3000
					});
					return;
				}
				if (countermeasures == "" || countermeasures == null || countermeasures == undefined) {
					api.toast({
						msg: '请填写【' + citemList[k].itemName + '】不符合项描述！',
						duration: 3000
					});
					return;
				}
				if (finishDates == "" || finishDates == null || finishDates == undefined) {
					api.toast({
						msg: '请选择【' + citemList[k].itemName + '】整改时间！',
						duration: 3000
					});
					return;
				}


				var mode = {
					itemid: itemid,
					citemname: citemList[k].itemName,
					countermeasures: countermeasures,
					finishDates: finishDates

				}
				citemListNew.push(mode)

			}
			console.log(JSON.stringify(citemListNew))
		}

		// var imgs = document.getElementsByTagName('img');
		// var names = [];
		// for (var i = 0; i < imgs.length; i++) {
		// 	var img = imgs[i];
		// 	var srcStr = img.getAttribute('src');
		// 	var arrs = srcStr.split('\/');
		// 	var nameStr = arrs[arrs.length - 1];
		// 	if ("add.jpg" != nameStr) {
		// 		names[i] = nameStr;
		// 	}
		// }
		// var picNames = JSON.parse(JSON.stringify(names));
		// var actualBeginDate = this.actualBeginDate;
		// var actualEndDate = this.actualEndDate;
		api.showProgress();
		//var rsCode = document.getElementById("rsCode").value;
		var serverUrl = localStorage.getItem('serverUrl');
		var url = serverUrl + "/app/saveTaskItem2SH";
		var un = localStorage.getItem('un');
		// var pw = localStorage.getItem('pw');
		// var serverIp = localStorage.getItem('serverIp');
		// var serverPort = localStorage.getItem('serverPort');
		// var serverProject = localStorage.getItem('serverProject');
		// var url1 = serverIp+":"+serverPort+"/"+serverProject;

		const submitButton = document.getElementById('submitButton');
		submitButton.style.pointerEvents = "none"

		var params = new Object();
		params.url = url;
		params.method = 'post';
		params.dataType = 'json';
		params.returnAll = 'false';
		params.timeout = 60;

		api.showProgress({
			title: '保存中...',
		});

		var data = {
			values: {
				un: un,
				// pw: pw,
				// url: url1,
				taskId: taskId,
				rowData: JSON.stringify(josnList),
				type: type,
				taskState: taskState,
				//rsCode: rsCode,
				actualBeginDate: actualBeginDate,
				actualEndDate: actualEndDate,
				processors: processors,
				areaSysid: areaSysid,
				measures: measures,
				finishDate: finishDate,
				countermeasure: countermeasure,
				picNames: picNames,
				citemListNew: citemListNew
			}
		};

		api.ajax({
			url: url,
			method: 'post',
			dataType: 'json',
			timeout: 300,
			returnAll: false,
			data: data
		}, function (ret, err) {
			if (ret) {
				var data = JSON.stringify(ret);
				var myobj = eval("(" + data + ")");
				//成功
				if (myobj.code == '0') {

					api.hideProgress();
					submitButton.style.pointerEvents = "auto"
					api.toast({
						msg: "保存成功",
						duration: 3000
					});
					//清空所有信息，重新扫设备选任务
					taskId = "";
					taskCode = "";
					itemIds = "";
					itemCodes = "";
					itemNames = "";
					itemModes = "";
					itemValues = "";
					josnList = [];

					HCIds = "";
					mrlGids = "";
					mrlCodes = "";
					mrlNames = "";
					mrlExNames = "";
					qtys = "";
					measureNames = "";
					consumeTypes = "";
					remarks = "";
					josnHCList = [];
					citemList = []
					citemresult = ""
					citemHtml = ""
					YqIds = "";
					mrlYqGids = "";
					mrlYqCodes = "";
					mrlYqNames = "";
					remarkYqs = "";
					josnYqList = [];
					closeWin();
				}
			} else {
				api.hideProgress();
				submitButton.style.pointerEvents = "auto"
				alert(JSON.stringify(err));
			}
		});
	}


	//返回按钮
	function closeWin() {
		api.closeWin({});
		var name = api.pageParam.name;
		api.execScript({
			name: 'lpaMntTask',
			script: 'cleanVariable()'
		});
	}
</script>

</html>